package com.cy.springboot04notice.service.impl;

import com.cy.springboot04notice.common.annotation.RequiredLog;
import com.cy.springboot04notice.common.annotation.RequiredTime;
import com.cy.springboot04notice.dao.SysNoticeDao;
import com.cy.springboot04notice.pojo.SysNotice;
import com.cy.springboot04notice.service.SysNoticeService;
import lombok.extern.java.Log;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
@Slf4j
public class SysNoticeServiceImpl implements SysNoticeService {

    @Resource
    private SysNoticeDao sysNoticeDao;

    @RequiredLog(operation = "添加公告信息")
    @Override
    public int saveNotice(SysNotice notice) {
        int i = sysNoticeDao.insertNotice(notice);
        return i;

    }

    @RequiredLog(operation = "查询公告信息")
    @Override
    public List<SysNotice> findNotices(SysNotice notice) {
        log.debug("start{}",System.currentTimeMillis());
        List<SysNotice> sysNotices = sysNoticeDao.selectNotices(notice);
        log.debug("end{}",System.currentTimeMillis());
        return sysNotices;
    }

    @RequiredLog(operation = "删除公告信息")
    @Override
    public int deleteById(Integer...ids) {
        int i = sysNoticeDao.deleteNotice(ids);
        if (i==0){
            throw new RuntimeException("记录可能不存在");
        }
        return i;
    }

    @RequiredLog(operation = "查询公告列表")//日志切面
    @RequiredTime//测试切面
    @Override
    public SysNotice findById(Integer id) {
        SysNotice sysNotice = sysNoticeDao.selectNoticeId(id);
        return sysNotice;
    }

    @RequiredLog(operation = "更改公告信息")
    @Override
    public int updateNotice(SysNotice notice) {
        int i = sysNoticeDao.updateNotice(notice);
        return i;
    }
}
